#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int maxn=10005;
const int maxm=maxn*2;

int g[maxn],dis[maxn],vis[maxn],siz[maxn],mx[maxn];
int v[maxm],w[maxm],nxt[maxm];
int en,k,ans,root,rt,dn;

inline void addEdge(const int &x,const int &y,const int &z){ v[en]=y;w[en]=z;nxt[en]=g[x];g[x]=en++;}

void getSize(int p,int f){
    siz[p]=1;mx[p]=1;
    for(int j=g[p];~j;j=nxt[j]){
        const int &tar=v[j];
        if(vis[tar]||f==tar) continue;
        getSize(tar,p);
        siz[p]+=siz[tar];
        if(siz[tar]>mx[p]) mx[p]=siz[tar];
    }
}
void getRoot(int p,int f){
    mx[p]=max(mx[p],siz[rt]-siz[p]);
    if(mx[p]<mx[root]) root=p;
    for(int j=g[p];~j;j=nxt[j]){
        const int &tar=v[j];
        if(vis[tar]||tar==f) continue;
        getRoot(tar,p);
    }
}
void getDis(int p,int d,int f){
    dis[dn++]=d;
    for(int j=g[p];~j;j=nxt[j]){
        const int &tar=v[j];
        if(vis[tar]||tar==f) continue;
        getDis(tar,d+w[j],p);
    }
}
int calc(int p,int d){
    int ans=0;
    dn=0;
    getDis(p,d,0);
    sort(dis,dis+dn);
    int i=0,j=dn-1;
    while(i<j){
        while(dis[i]+dis[j]>k&&i<j) j--;
        ans+=j-i;
        i++;
    }
    return ans;
}
void solve(int p){
    root=0;
    getSize(p,0);
    getRoot(rt=p,0);
    ans+=calc(root,0);
    vis[root]=1;
    for(int j=g[root];~j;j=nxt[j]){
        const int &tar=v[j];
        if(vis[tar]) continue;
        ans-=calc(tar,w[j]);
        solve(tar);
    }
}

int main(){
    int n;
    while(~scanf("%d%d",&n,&k)){
        if(!n&&!k) break;
        memset(g,-1,sizeof(g));
        memset(vis,0,sizeof(vis));
        en=0;
        mx[0]=siz[0]=~0U>>1;

        for(int i=1;i<n;i++){
            int x,y,z;
            scanf("%d%d%d",&x,&y,&z);
            addEdge(x,y,z);
            addEdge(y,x,z);
        }

        ans=0;
        solve(1);
        printf("%d\n",ans);
    }

    return 0;
}

